<%--
  Created by IntelliJ IDEA.
  User: a1557
  Date: 2020/10/13
  Time: 20:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
    <head>
        <title>首页</title>
        <%-- 不以/开始的相对路径,找资源以路径为基准,经常容易出事
             以/开始的以服务器路径为准 : http://localhost:8080/
         --%>

        <% pageContext.setAttribute("APP_PATH", request.getContextPath());%>


        <%--引入样式--%>
        <link href="${APP_PATH}/static/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
        <script type="${APP_PATH}/static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>

        <script type="text/javascript" src="static/"></script>
    </head>
    <body>
        <%--搭建显示页面--%>
        <div class="container">
            <%--标题--%>
            <div class="row">
                <div class="col-lg-12">
                    <h1>简单的增删改查</h1>
                </div>
            </div>
            <%--按钮--%>
            <div class="row">
                <div class="col-md-4 col-md-offset-8">
                    <button class="btn btn-primary">新增</button>
                    <button class="btn btn-danger">删除</button>
                </div>
            </div>
            <%--显示表格--%>
            <div class="row">
                <div class="row">
                    <div class="col-md-12">
                        <table class="table table-hover">
                            <thead>
                                <tr class="p-3 mb-2 bg-success text-white">
                                    <th scope="col">ID</th>
                                    <th scope="col">员工名</th>
                                    <th scope="col">性别</th>
                                    <th scope="col">邮箱</th>
                                    <th scope="col">部门名</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <c:forEach items="${pageInfo.list}" var="emp">
                                <tr>
                                    <th>${emp.empId}</th>
                                    <th>${emp.empName}</th>
                                    <th>${emp.gender=="M"?"男":"女"}</th>
                                    <th>${emp.email}</th>
                                    <th>${emp.department.deptName}</th>
                                    <th>
                                        <button class="btn btn-primary btn-sm">
                                            <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                                            编辑
                                        </button>
                                        <button class="btn btn-danger btn-sm">
                                            <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
                                            删除
                                        </button>
                                    </th>
                                </tr>
                            </c:forEach>

                        </table>
                    </div>
                </div>

                <%--pegeNum : 页数
                    pages : 总共的页数
                    total : 总记录数
                    navigatepageNums : 连续显示的页码
                --%>
                <%--显示分页信息--%>
                <div class="row">
                    <%--分页文件信息--%>
                    <div class="col-md-6">
                        当前 <span class="text-danger font-weight-bold">${pageInfo.pageNum}</span> 页,
                        总共 <samp class="text-danger font-weight-bold">${pageInfo.pages}</samp> 页,
                        总共 <span class="text-danger font-weight-bolder">${pageInfo.total}</span> 条记录
                    </div>

                    <%--分页条信息--%>
                    <div class="col-md-6">
                        <nav aria-label="Page navigation example">
                            <ul class="pagination">
                                <li class="page-item"><a class="page-link" href="${APP_PATH}/emps?pn=1">首页</a></li>

                                <%--判断是否有上一页--%>
                                <c:if test="${pageInfo.hasPreviousPage}">
                                    <li class="page-item">
                                        <a class="page-link" href="${APP_PATH}/emps?pn=${pageInfo.pageNum-1}"
                                           aria-label="Previous">
                                            <span aria-hidden="true">&laquo;</span>
                                        </a>
                                    </li>
                                </c:if>


                                <%--分页条的页码的遍历--%>
                                <c:forEach items="${pageInfo.navigatepageNums}" var="Num">
                                    <%--判断显示的是当前页码,是的话就加上按下样式--%>
                                    <c:if test="${Num == pageInfo.pageNum}">
                                        <li class="active"><a class="page-link"
                                                              href="${APP_PATH}/emps?pn=${Num}">${Num}</a></li>
                                    </c:if>

                                    <c:if test="${Num != pageInfo.pageNum}">
                                        <li class="page-item"><a class="page-link"
                                                                 href="${APP_PATH}/emps?pn=${Num}">${Num}</a></li>
                                    </c:if>

                                </c:forEach>

                                <%--判断是否有最后一页--%>
                                <c:if test="${pageInfo.hasNextPage}">
                                    <li class="page-item">
                                        <a class="page-link" href="${APP_PATH}/emps?pn=${pageInfo.pageNum+1}"
                                           aria-label="Next">
                                            <span aria-hidden="true">&raquo;</span>
                                        </a>
                                    </li>
                                </c:if>
                                <li class="page-item"><a class="page-link" href="${APP_PATH}/emps?pn=${pageInfo.total}">末页</a>
                                </li>
                            </ul>
                        </nav>
                    </div>
                </div>
            </div>
        </div>


    </body>
</html>
